package com.dstz.bpm.engine.plugin.session.impl;

import com.dstz.bpm.api.constant.ActionType;
import com.dstz.bpm.api.constant.EventType;
import com.dstz.bpm.api.engine.action.cmd.BaseActionCmd;
import com.dstz.bpm.api.engine.context.BpmContext;
import com.dstz.bpm.api.model.inst.IBpmInstance;
import com.dstz.bpm.engine.action.cmd.DefualtTaskActionCmd;
import com.dstz.bpm.engine.plugin.session.BpmExecutionPluginSession;
import com.dstz.bus.api.model.IBusinessData;
import com.dstz.sys.util.ContextUtil;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.delegate.VariableScope;

public class DefaultBpmExecutionPluginSession extends HashMap<String, Object> implements BpmExecutionPluginSession {
   private static final long serialVersionUID = 4225343560381914372L;
   private Map<String, IBusinessData> cc;
   private EventType cd;
   private VariableScope variableScope;
   private IBpmInstance bpmInstance;

   public DefaultBpmExecutionPluginSession() {
      BaseActionCmd submitCmd = (BaseActionCmd)BpmContext.submitActionModel();
      ActionType actionType = submitCmd.getActionType();
      this.put("actionCmd", BpmContext.getActionModel());
      this.put("currentUser", ContextUtil.getCurrentUser());
      this.put("submitActionDesc", actionType.getName());
      this.put("submitActionName", actionType.getKey());
      this.put("isTask", false);
      if (submitCmd instanceof DefualtTaskActionCmd) {
         DefualtTaskActionCmd taskCmd = (DefualtTaskActionCmd)submitCmd;
         this.put("submitOpinion", taskCmd.getOpinion());
         if (taskCmd.getBpmTask() != null) {
            this.put("isTask", true);
            this.put("submitTaskName", taskCmd.getBpmTask().getName());
         }
      }

   }

   public Map<String, IBusinessData> getBoDatas() {
      return this.cc;
   }

   public void setBoDatas(Map<String, IBusinessData> boDatas) {
      this.putAll(boDatas);
      this.cc = boDatas;
   }

   public IBpmInstance getBpmInstance() {
      return this.bpmInstance;
   }

   public void setBpmInstance(IBpmInstance bpmInstance) {
      this.put("bpmInstance", bpmInstance);
      this.bpmInstance = bpmInstance;
   }

   public EventType getEventType() {
      return this.cd;
   }

   public void setEventType(EventType eventType) {
      this.put("eventType", eventType.getKey());
      this.cd = eventType;
   }

   public VariableScope getVariableScope() {
      return this.variableScope;
   }

   public void setVariableScope(VariableScope variableScope) {
      this.put("variableScope", variableScope);
      this.variableScope = variableScope;
   }
}
